package com.balabala.gym_user.controller.admin;

import com.balabala.gym_enum.ResultEnum;
import com.balabala.gym_user.pojo.entity.CardConsumeRecord;
import com.balabala.gym_user.service.CardConsumeRecordService;
import com.balabala.result.Result;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 何涛
 * @Date: 2023/05/02/ 19:04
 * @description 用户会员卡消费信息
 */
@RestController
@RequestMapping("/admin/cardConsumeRecord")
@Api(tags = "用户会员卡消费记录后台接口")
@CrossOrigin
@Slf4j
public class CardConsumeRecordController {
    @Autowired
    CardConsumeRecordService cardConsumeRecordService;
    @PostMapping("add")
    @ApiOperation("添加用户会员卡消费记录")
    public Result addCardConsumeRecord(@RequestBody CardConsumeRecord cardConsumeRecord)
    {
        log.info("添加一条用户会员卡消费记录,添加信息为：{}",cardConsumeRecord);
        return Result.ok(ResultEnum.GENERALLY_SUCCESS,cardConsumeRecordService.save(cardConsumeRecord));
    }
    @ApiOperation("根据用户会员卡id查询所有消费记录")
    @GetMapping("/{userVipCardId}")
    public Result findCardConsumeRecordByUserCardId(@PathVariable Long userVipCardId)
    {
        log.info("查找用户会员卡的消费记录，用户会员卡id：{}",userVipCardId);
        return Result.ok(ResultEnum.GENERALLY_SUCCESS,cardConsumeRecordService.list(new LambdaQueryWrapper<CardConsumeRecord>().eq(CardConsumeRecord::getUserCardId,userVipCardId)));
    }
}
